package com.unknown.world

import com.unknown.BaseEntity;

import grails.converters.JSON;

class RoomTile extends BaseEntity implements Comparable<RoomTile> {
	static {
		JSON.registerObjectMarshaller(RoomTile){
			def map = [:]
			map['row'] = it.row
			map['col'] = it.col
			map['tileId'] = it.tile.tileId
			return map;
		}
	}

    static hasOne  = [tile:Tile]

	int row
	int col
	
	int compareTo(RoomTile other){
		int result = row - other.row;
		if( result == 0 ){
			result = col - other.col;
		}
		return result;
	}
	
	int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + col;
		result = prime * result + row;
		return result;
	}
	
	public boolean equals(Object obj) {
		if (getClass() != obj.getClass())
			return false;
		RoomTile other = (RoomTile) obj;
		if (col != other.col)
			return false;
		if (row != other.row)
			return false;
		return true;
	}
}
